$(function () {
    $.ajax({
        url: '/data/list',
        type: 'get',
        dataType: "json",
        // contentType: 'application/json;charset=UTF-8',
        // data: JSON.stringify(data),
        // async: true,
        processData: false,   // 不处理发送的数据
        contentType: false,   // 不设置Content-Type请求头
        success:
            function (res) {
                if (res.code == 200) {
                    showdata(res);
                    // window.location.href = '/data/index';
                    console.log(res);

                } else {
                    $.toast({
                        title: '通知',
                        subtitle: '5秒前',
                        content: res.msg,
                        type: 'info',
                        delay: 20000,
                        pause_on_hover: false
                    });
                }
            }
    })




function showdata(res){
    // res.data.dataVO.data=donutData.labels[0];
    // res.data.dataVO.articleTotal=bar-data.data[1];
    // res.data.dataVO.commentTotal=datasets.data;


    var bar_data = {
        data: [[1,res.data.commentTotal[0]], [2, res.data.commentTotal[1]], [3, res.data.commentTotal[2]], [4, res.data.commentTotal[3]], [5, res.data.commentTotal[4]], [6, res.data.commentTotal[5]]],
        bars: {show: true}
    }
    $.plot('#bar-chart', [bar_data], {
        grid: {
            borderWidth: 1,
            borderColor: '#f3f3f3',
            tickColor: '#f3f3f3'
        },
        series: {
            bars: {
                show: true, barWidth: 0.5, align: 'center',
            },
        },
        colors: ['#3c8dbc'],
        xaxis: {
            ticks: [[1, res.data.date[0]], [2, res.data.date[1]], [3, res.data.date[2]], [4, res.data.date[3]], [5, res.data.date[4]], [6, res.data.date[5]]]
        }
    })

    var donutData        = {
        labels: [
            res.data.date[0],
            res.data.date[1],
            res.data.date[2],
            res.data.date[3],
            res.data.date[4],
            res.data.date[5],
        ],
        datasets: [
            {
                data:res.data.articleTotal,
                backgroundColor : ['#f56954', '#00a65a', '#f39c12', '#00c0ef', '#3c8dbc', '#d2d6de'],
            }
        ]
    }
    var pieChartCanvas = $('#pieChart').get(0).getContext('2d')
    var pieData        = donutData;
    var pieOptions     = {
        maintainAspectRatio : false,
        responsive : true,
    }
    //Create pie or douhnut chart
    // You can switch between pie and douhnut using the method below.
    var pieChart = new Chart(pieChartCanvas, {
        type: 'pie',
        data: pieData,
        options: pieOptions
    })
}


})